1st Order Spatial Point Pattern Analysis: Kernel Density Estimation

Overview

We are using Spatial Point Pattern Analysis to answer these questions: 1. Are the locations of room rentals in Jakarta randomly distributed? 2. If not randomly distributed, where are the locations with high concentration of room rentals?

Packages

We are using five packages, loaded with the above chunk:

  1. sf to process geospatial data
  2. spatstat to perform the spatial point pattern analysis
  3. raster to convert the image output from spatstat into raster format
  4. maptools to handle ppp data
  5. tmap to plot the maps
  6. tidyverse for data wrangling

Data

Jakarta Data Loading

Reading layer `jakarta' from data source 
  `C:\Users\yozaf\SMUY3S2\Geospatial\IS415-GAA\Take-home_Ex\Take-home_Ex03\data\geospatial\rds' 
  using driver `ESRI Shapefile'
Simple feature collection with 260 features and 27 fields
Geometry type: MULTIPOLYGON
Dimension:     XY
Bounding box:  xmin: 106.6862 ymin: -6.370731 xmax: 106.9733 ymax: -6.088227
Geodetic CRS:  WGS 84 + EGM2008 height

Note that the data is in a WGS 84 + EGM2008 height CRS. We can convert it to WGS84 with the chunk below

We can use qtm() to get a simple map of the jakarta data

Mamikos Data Loading

      _id           price_monthly         latitude        longitude    
 Min.   : 1728989   Min.   :  350000   Min.   :-6.286   Min.   :106.7  
 1st Qu.:32773220   1st Qu.: 1000000   1st Qu.:-6.239   1st Qu.:106.8  
 Median :55360905   Median : 1600000   Median :-6.202   Median :106.8  
 Mean   :54976650   Mean   : 1868027   Mean   :-6.207   Mean   :106.8  
 3rd Qu.:77177521   3rd Qu.: 2400000   3rd Qu.:-6.178   3rd Qu.:106.9  
 Max.   :99992091   Max.   :15000000   Max.   :-6.130   Max.   :106.9  
                                                                       
     gender       area_city_keyword  area_subdistrict       status      
 Min.   :0.0000   Length:8969        Length:8969        Min.   :0.0000  
 1st Qu.:0.0000   Class :character   Class :character   1st Qu.:0.0000  
 Median :1.0000   Mode  :character   Mode  :character   Median :0.0000  
 Mean   :0.8145                                         Mean   :0.6262  
 3rd Qu.:2.0000                                         3rd Qu.:2.0000  
 Max.   :2.0000                                         Max.   :2.0000  
                                                                        
     size             fac_room          fac_share           fac_bath        
 Length:8969        Length:8969        Length:8969        Length:8969       
 Class :character   Class :character   Class :character   Class :character  
 Mode  :character   Mode  :character   Mode  :character   Mode  :character  
                                                                            
                                                                            
                                                                            
                                                                            
   fac_near           fac_park           kos_rule          fac_price        
 Length:8969        Length:8969        Length:8969        Length:8969       
 Class :character   Class :character   Class :character   Class :character  
 Mode  :character   Mode  :character   Mode  :character   Mode  :character  
                                                                            
                                                                            
                                                                            
                                                                            
 owner_user_id     building_year  is_singgahsini   is_apik       
 Min.   :   6350   Min.   :   0   Mode :logical   Mode :logical  
 1st Qu.:1338529   1st Qu.:2015   FALSE:8499      FALSE:8853     
 Median :3475312   Median :2019   TRUE :470       TRUE :116      
 Mean   :3535335   Mean   :1991                                  
 3rd Qu.:5480051   3rd Qu.:2021                                  
 Max.   :8163159   Max.   :2024                                  
 NA's   :5         NA's   :984                                   
  is_elite       number_success_owner_trx number_success_kos_trx
 Mode :logical   Min.   :    0.0          Min.   :  0.000       
 FALSE:8969      1st Qu.:    0.0          1st Qu.:  0.000       
                 Median :    0.0          Median :  0.000       
                 Mean   :  688.7          Mean   :  3.587       
                 3rd Qu.:    3.0          3rd Qu.:  3.000       
                 Max.   :10961.0          Max.   :241.000       
                                                                
     url           
 Length:8969       
 Class :character  
 Mode  :character  
                   
                   
                   
                   

Note that the mamikos data has its location in the latitude and longitude columns, which we can convert to geometry in an sf dataframe

Coordinate Reference System:
  User input: EPSG:4326 
  wkt:
GEOGCRS["WGS 84",
    ENSEMBLE["World Geodetic System 1984 ensemble",
        MEMBER["World Geodetic System 1984 (Transit)"],
        MEMBER["World Geodetic System 1984 (G730)"],
        MEMBER["World Geodetic System 1984 (G873)"],
        MEMBER["World Geodetic System 1984 (G1150)"],
        MEMBER["World Geodetic System 1984 (G1674)"],
        MEMBER["World Geodetic System 1984 (G1762)"],
        MEMBER["World Geodetic System 1984 (G2139)"],
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]],
        ENSEMBLEACCURACY[2.0]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    USAGE[
        SCOPE["Horizontal component of 3D system."],
        AREA["World."],
        BBOX[-90,-180,90,180]],
    ID["EPSG",4326]]

We can plot the map with tmap

School Data Loading

Since we have an rds file containing locations of schools, we can load it with read_rds()

Data Wrangling

Converting to ppp

Since spatstat requires data in ppp object form, we can use as.ppp to directly convert sf to ppp. However, we have to change the CRS to 23833 or DGN95, which is Indonesia’s CRS System, as ppp file requires projected geometries (not WGS84)

Checking for duplicates

[1] FALSE

Since there are no duplicates, we can go on to the next step

Creating owin object

We can make an owin object to confine our analysis to only Jakarta

Combining Jakarta and Mamikos Data

We will extract only rental rooms within the owin object

First-Order Spatial Point Analysis

Deriving Kernel Density Estimation

We are using adaptive bandwidth

Converting output to grid

Converting grid to raster

class      : RasterLayer 
dimensions : 128, 128, 16384  (nrow, ncol, ncell)
resolution : 248.5865, 245.3833  (x, y)
extent     : 552807.9, 584626.9, 794365.4, 825774.4  (xmin, xmax, ymin, ymax)
crs        : NA 
source     : memory
names      : v 
values     : -7.371997e-20, 0.0006103475  (min, max)
class      : RasterLayer 
dimensions : 128, 128, 16384  (nrow, ncol, ncell)
resolution : 248.5865, 245.3833  (x, y)
extent     : 552807.9, 584626.9, 794365.4, 825774.4  (xmin, xmax, ymin, ymax)
crs        : NA 
source     : memory
names      : v 
values     : 5.655212e-17, 0.001577487  (min, max)

Note that the CRS is NA, so we can assign the CRS by ourselves

Visualizing Output in Tmap

For the rooms

For the schools

Overlay of both

Comparing KDE in Different Cities in Jakarta

First, we extract the 5 cities

Next, we convert them to owin

And combine them with the mamikos data

KDE For Jakarta Barat

Storyboard

User Inputs Sidebar

When implementing this to the Shiny App, we can make it dynamic by implementing this in our sidebar:

  1. Implementing input for cities: For analyzing Kernel Density Estimates with a specific city, instead of the whole DKI Jakarta, we can use a select input where users can choose which city they want, or Jakarta as a whole

  2. Educational Institutions: If users have any requirements regarding the educational institutions displayed (e.g: they only want to analyze nearby universities or wants to exclude primary schools), they can use a checkbox to select which levels will be analyzed.

  3. Implementing Kernel methods. Users can choose which kernel methods they want for the KDE analysis using a dropdown

Main Panel

The main panel will be displaying the KDE map, with three separate tabs to display:

  1. The combined overlay of both Mamikos rooms and schools
  2. Only the Mamikos rooms
  3. Only schools

Storyboard